<?php

/**
 * @Author: wuchenge
 * @Date: 2020-11-30 15:00:42
 * @email: ligui0506@sina.com
 * @descript: 消息模型
 */

namespace App\Models;

class Message extends Model
{
    protected $table    = 'messages';
    protected $guarded  = ['id', 'created_at', 'updated_at'];
    protected $fillable = ['message', 'language', 'error_code'];

    const FAILED  = 'failed';
    const SUCCESS = 'failed';

    /**
     * 根据 消息码 和 语言 获取对应的消息
     * @param  [type] $code     [消息码]
     * @param  [type] $language [语言]
     * @return [type]           [description]
     */
    public static function getMessage($code, $language)
    {
        $message = self::select(['message'])
            ->where('error_code', $code)
            ->where('language', $language)
            ->first();
        // if ($message && $message->isNotEmpty()) {
        if ($message) {
            return $message->message;
        }

        return self::FAILED;
    }
}
